<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微擎示例应用</title>
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="/addons/we7_thinkphp/public/static/style/module/css/font/iconfont.css?v=1.0.1" media="all">
    <link rel="stylesheet" type="text/css" href="/addons/we7_thinkphp/public/static/plug/layui/css/layui.css?v=2.2.2" media="all">
    <link rel="stylesheet" type="text/css" href="/addons/we7_thinkphp/public/static/style/module/css/main.css?v2.0.1-simple" media="all">
</head>

<body>
<div class="layui-fluid larry-wrapper">
    <div class="layui-row layui-col-space30">
        <div class="layui-col-xs24">
            <section class="panel panel-padding">
                <div class="layui-form">
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input class="layui-input" id="keyword" name="keyword" placeholder="请输入关键字">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button lay-submit class="layui-btn" lay-filter="search" data-type="keyword">搜索</button>
                    </div>
                </div>
            </section>

            <section class="panel panel-padding">
                <div class="group-button">
                    <button class="layui-btn layui-btn-sm modal" data-params='{"content":"./index.php?c=site&a=entry&m=we7_thinkphp&do=article&act=article_add", "title":"添加文章","type":"2",maxmin:"true",area:"900px,700px"}'>
                    <i class="iconfont">&#xe649;</i> 添加
                    </button>
                </div>
                <div class="layui-form">
                    <table class="layui-table" lay-data="{height:'full-200', url:'./index.php?c=site&a=entry&m=we7_thinkphp&do=article&act=article',page:'true',limit:20,id:'article'}" lay-filter="article">
                        <thead>
                        <tr>
                            <th lay-data="{field:'id', width:'10%', sort: true, align:'center'}">编号</th>
                            <th lay-data="{field:'title',  width:'10%',align:'left'}">标题</th>
                            <th lay-data="{field:'description', width:'20%',  align:'center'}">简介</th>
                            <th lay-data="{field:'creattime', width:'30%',  align:'center',templet:'#createtime'}">创建时间</th>
                            <th lay-data="{fixed: 'right', width:'30%', align:'center', toolbar: '#barDemo'}">操作</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </section>
        </div>
    </div>
</div>

</body>

<script type="text/html" id="createtime">
    <div class="">
        {{#
			function getLocalTime(nS) {
                return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
            }
        }}
        {{ getLocalTime(d.creattime) }}
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs  layui-bg-green modal" data-params='{content:"./index.php?c=site&a=entry&m=we7_thinkphp&do=article&act=article_edit&id={{d.id}}",type:"2", title:"{{d.title}}",maxmin:"true",area:"900px,700px"}' lay-event="edit" data-edit = "{{ d.id }}">修改</a>
    <a class="layui-btn layui-bg-red layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/javascript" src="/addons/we7_thinkphp/public/static/plug/layui/layui.js?v=2.2.2"></script>
<script type="text/javascript" src="/addons/we7_thinkphp/public/static/style/module/js/common.js?v=2.0.1"></script>

<script>
    layui.config({
        base: '/addons/we7_thinkphp/public/static/style/module/js/',
        version: "2.0.1-simple"
    }).extend({
        jqelem: 'jqmodules/jqelem',
        jqmenu: 'jqmodules/jqmenu',
        tabmenu: 'jqmodules/tabmenu',
        jqbind: 'jqmodules/jqbind',
        jqtags: 'jqmodules/jqtags',
        jqform: 'jqmodules/jqform',
        jqcitys: "jqmodules/jqcitys"
    })
    layui.use(['jquery','jqbind',  'jqform', 'table', 'laydate'],function(){
        var $ = layui.jquery,
            jqbind = layui.jqbind,
            form = layui.jqform,
            laydate = layui.laydate,
            table = layui.table;

        table.on('tool(article)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定删除吗？', function(index){
                    obj.del();
                    layer.close(index);
                    param={id:data.id};
                    ajax("./index.php?c=site&a=entry&m=we7_thinkphp&do=article&act=article_del",param,'');
                });
            }else if (obj.event === 'edit') {
                var _this = $("tr").find('[data-edit="'+data.id+'"]');
                jqbind.modal(_this);
            }
        });

        var active = {
            keyword: function(){
                var keyword = $('#keyword').val();
                where = {keyword:keyword};
                tableReload(where);
            },
        };


        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        function ajax(url,param,msg,where,currPage)
        {
            $.getJSON(url,param, function(res){
                if(res.code === 0)
                {
                    layer.msg(res.msg);
                    if(where) tableReload(where,currPage)
                }
                else
                {
                    layer.msg(res.msg);
                }
            });
        }
        function tableReload(where,currPage)
        {
            var currPage=currPage ? currPage : $('.layui-laypage-skip.layui-input').val();
            table.reload('article', {
                page: {
                    curr: currPage
                }
                ,where: where
            });
        }
    })

</script>

</html>